package net.xumf.web.controller.member.module;

import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import net.xumf.domain.master.SystemModule;
import net.xumf.service.master.SystemModuleService;
import net.xumf.support.model.ResponseResult;
import net.xumf.support.model.dto.ModuleModifyDTO;
import net.xumf.support.model.dto.PageDTO;
import net.xumf.support.model.vo.ModuleBaseVO;
import net.xumf.support.model.vo.PageVO;
import net.xumf.web.controller.common.BaseControllerImpl;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(value = "模块管理", description = "模块")
@RequestMapping("member/modules")
public class SystemModuleController extends BaseControllerImpl<PageDTO, SystemModuleService, SystemModule, Integer> {

    @ApiOperation(value = "获取模块数据")
    @GetMapping("/parent/{parentId}")
    public PageVO getModuleAll(@PathVariable Integer parentId, @ApiParam PageDTO pageDTO) {
//        if (StringUtils.isEmpty(pageDTO.getSearchString())) {
//            return service.getSystemModules(pageDTO);
//        } else {
        return service.getSystemModulesByParentIdAndPage(parentId, pageDTO);
//        }
    }

    @ApiOperation(value = "根据parentId获取模块数据")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "parentId", value = "父模块id", required = true, dataTypeClass = Integer.class, paramType = "queryer", example = "0为顶级模块"))
    @GetMapping("/tree/{parentId}")
    public ResponseResult getModuleByParentId(@PathVariable Integer parentId) {
        return ResponseResult.success(service
                .getSystemModulesByParentId(parentId));
    }

    @ApiOperation(value = "获取用户拥有的菜单模块")
    @GetMapping("/menu")
    public List<? extends ModuleBaseVO> getMenuModule() {
        return service.getWebPageMenuModuleBy();
    }

    @ApiOperation(value = "获取用户拥有的树形模块")
    @GetMapping("/tree")
    public List<? extends ModuleBaseVO> getTreeModule() {
        return service.getWebPageTreeModuleBy();
    }

    @ApiOperation(value = "根据parentId获取所有table模块")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "parentId", value = "父模块id", required = true, dataTypeClass = Integer.class, paramType = "queryer", example = "0为顶级模块"))
    @GetMapping("/table/{parentId}")
    public ResponseResult getModuleForTableByParentId(@PathVariable Integer parentId) {
        return ResponseResult.success(service.getModuleForTableByParentId(parentId));
    }

    @ApiOperation(value = "获取所有table模块")
    @GetMapping("/table")
    public ResponseResult getModuleForTable() {
        return ResponseResult.success(service.getModuleForTable());
    }

    @ApiOperation(value = "获取前端所需树形模块与角色拼接")
    @GetMapping("/roles")
    public ResponseResult getRole() {
        return ResponseResult.success(service.getModuleAndRoleForTree());
    }

    @ApiOperation(value = "获取角色获取权限的ztree模型")
    @ApiImplicitParam(name = "id", value = "角色id", required = true, dataTypeClass = Integer.class, paramType = "path")
    @GetMapping("/role/{id}/ztree")
    public ResponseResult getZtreeVO(@PathVariable Integer id) {
        return ResponseResult.success(service.getZtreeVO(id));
    }

}
